package com.shiguiwu.springmybatis.spring.cycle;


import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;


/**
 * @description: 循环依赖问题
 * @author: stone
 * @date: Created by 2021/4/26 12:21
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.cycle
 */
@ComponentScan
public class CycleTests {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(CycleTests.class);
        context.refresh();

        //报错===============================早期的bean和生成的对象不一致

        //解决
        //创建一个BeanFactoryPostProcessor：BeanFactory后置处理器
//        context.addBeanFactoryPostProcessor(beanFactory -> {
//            if (beanFactory instanceof DefaultListableBeanFactory) {
////将allowRawInjectionDespiteWrapping设置为true
//                ((DefaultListableBeanFactory)
//                        beanFactory).setAllowRawInjectionDespiteWrapping(true);
//            }
//        });

        Mather bean = context.getBean(Mather.class);
        Father bean1 = context.getBean(Father.class);
        bean.method2();
        //System.out.println(bean == bean1.getMather());
    }









}



